home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //////////////////////////////////////////////////////////////////////////////
- // This file contains the MEL script to create the Paintable Attribute Menu
- //////////////////////////////////////////////////////////////////////////////
- global proc artAttrCreateMenuItems(
- string $parent,
- string $paintAttr
- )
- //
- // Description:
- // Creates a menu that shows all the paintable attributes.
- //
- // NOTE: paintAttr are sorted by the paintable node type.
- //
- {
- string $artCommand = "artAttrCtx";
-
- string $paintableItems[];
- tokenize( $paintAttr, " ", $paintableItems );
-
- int $size = size($paintableItems);
- if ( $size == 0 )
- return;
-
- string $menu, $menuLabel, $nodeMenuLabel;
- string $attrName;
-
- string $buffer[];
- int $i, $j;
-
- // Submenu counters.
- int $setParentCount = 0;
- int $menuItemCount = 0;
- for( $i = 0; $i < $size; $i++ ) {
- if ( "" == $paintableItems[$i] )
- continue;
-
- tokenize( $paintableItems[$i], ".", $buffer );
-
- // Create a paintable node submenu
- // if necessary.
- if ( $buffer[0] != $nodeMenuLabel ) {
- // Get back to the proper parent widget.
- for ($j = 0; $j < $setParentCount; $j++ ) {
- setParent ..;
- }
-
- // Reset the submenu counters.
- $setParentCount = 0;
- $menuItemCount = 0;
-
- // End the previous node subMenu.
- if ( $i > 0 ) {
- setParent -m $parent;
- }
-
- // Start a new node Menu;
- $nodeMenuLabel = $buffer[0];
- menuItem -subMenu true -l $nodeMenuLabel;
- }
-
- if ( $menuItemCount == 30 ) {
- // If there are more than 30 paintable nodes
- // we need to split the menu into submenus
- // - otherwise it does not fit on the
- // screen.
- menuItem -subMenu true -l "more ... ";
- $setParentCount ++;
-
- $menuItemCount = 0;
- }
-
- $menuLabel = $buffer[1] + "-" + $buffer[2];
- string $arribute = $buffer[0] + "." + $buffer[1] + "." + $buffer[2];
-
- $menu = `menuItem -l $menuLabel`;
- menuItem -e
- -c ("artSetToolAndSelectAttr( \"" + $artCommand + "\", \"" + $arribute + "\" )")
- $menu;
-
- $menuItemCount ++;
- }
-
- // Get back to the proper parent widget.
- for ($i = 0; $i<$setParentCount; $i++ ) {
- setParent ..;
- }
- setParent -m $parent;
- }
-
-
- global proc artSetToolAndSelectAttr(
- string $artCommand,
- string $attribute
- )
- //
- // Description:
- // Set a new tool if require and select an initial attribute.
- //
- {
- source "artAttrCallback.mel";
-
- string $currentContext = `currentCtx`;
- string $currTool = `contextInfo -c $currentContext`;
-
- // Check if we are in the right tool.
- string $buf[];
- tokenize( $attribute, ".", $buf );
- if ( size($buf) < 3 )
- return;
-
- string $paintableNodeType = $buf[0];
- string $paintableNodeName = $buf[1];
- string $paintableAttribute = $buf[2];
-
- if ( $paintableNodeType == "skinCluster" ) {
- // Check if this is skin paint weight tool.
- if ( $currTool != "artAttrSkin" ) {
- // Set the Skin Paint Weight tool.
- artAttrSkinToolScript( 4 );
- }
- } else if ( $paintableNodeType == "mesh" &&
- ($paintableAttribute == "vertexColorRGB" || $paintableAttribute == "vertexFaceColorRGB" ) ) {
- // Check if this is paint vertex color tool.
- if ( $currTool != "artAttrColorPerVertex" ) {
- if ( $paintableAttribute == "vertexColorRGB" ) {
- // Set the Paint Vertex Color itool.
- artAttrColorPerVertexToolScript( 5 );
- } else {
- artAttrColorPerVertexToolScript( 6 );
- }
- }
- } else {
- // You can only paint weights for polyReduce on a mesh node
- // upstream of the polyReduce node. This is because painting weights
- // on the mesh being reduced changes the topology and scrambles the
- // painted vertices.
- // So, here, we march up stream from the reduce node until
- // a valid mesh is found, and set that as the mesh being painted.
- //
- // The recommended way for you to use paint weights is to invoke the
- // command with the replaceOriginal flag off (or the Keep Original
- // option checked).
- //
- if ( $paintableNodeType == "polyReduce" ) {
- // get all upstream nodes
- //
- string $upstreamNodes[] = `listHistory $paintableNodeName`;
- int $i = 0;
- string $node = "";
- int $found = false;
- // march through upstream nodes looking for a valid mesh
- //
- for ($node in $upstreamNodes ) {
- string $nodeType = `nodeType $node`;
-
- // only poly meshes are valid for polyReduce
- //
- if ( $nodeType == "mesh" ) {
- int $isVisible = `getAttr( $node + ".visibility" )`;
- int $isIntermediate = `getAttr( $node + ".intermediateObject" )`;
- int $isTemplated = `getAttr( $node + ".template" )`;
-
- // the node must be visible and not intermediate
- //
- if ( $isVisible && !$isIntermediate ) {
- // Un-template an otherwise valid node (so we can select it)
- //
- if ( $isTemplated ) {
- setAttr( $node + ".template", false );
- warning($paintableNodeName + " can not accept templated nodes as input. Un-templating " + $node + "." );
- }
- $found = true;
- break;
- }
- }
- }
- // No valid upstream meshes.
- //
- if ( !$found ) {
- string $errorMsg = "Can't paint weights on the reduced mesh.\n";
- $errorMsg += "// Turn Keep Original on in the Reduce options and";
- $errorMsg += " paint weights on the original.";
- error( $errorMsg );
- return;
- } else {
- // found a valid mesh. Pick it as the mesh being painted.
- //
- select $node;
- }
- }
- if ( $currTool != "artAttr" ) {
- // Set the general Attribue Paint Tool.
- artAttrToolScript( 4, "" );
- }
- }
-
- // Set the selected attribute as paintable.
- artAttrSelected( $artCommand, $attribute );
- }
-